## CCES descriptives

library(tidyverse)

cces_panel = read_stata("cces_panel.dta")

## For descriptives, drop people who have NA on the contact measure 
cces_panel = cces_panel %>% filter(!is.na(contact))

## Figure A1
cces_panel %>% 
  count(contact) %>% 
  mutate(perc = n / nrow(cces_panel)*100)  -> contact_shares

shares = ggplot(contact_shares, aes(x = factor(contact), y = perc)) + 
  geom_bar(stat = "identity",color="black", fill="gray") +
  geom_text(aes(label=
                  paste0(I(round(perc, digits = 2)), "%")), 
            position=position_dodge(width=0.9), vjust=-0.45, size = 3) +
  scale_x_discrete(labels= c("0", "1", "2", "3", "4")) +
  labs(x = "Number of Types of Contact", y = "Percent of Respondents") +
  ylim(0, 40) +
  theme_bw()


## Figure A2
## % of respondents in each contact value -- by election cycle
cces_panel10 = cces_panel %>% filter(year == 2010)
cces_panel12 = cces_panel %>% filter(year == 2012)
cces_panel14 = cces_panel %>% filter(year == 2014)

cces_panel10 %>% 
  count(contact) %>% 
  mutate(perc = n / nrow(cces_panel10)*100, year=2010) -> contact_shares10

cces_panel12 %>% 
  count(contact) %>% 
  mutate(perc = n / nrow(cces_panel12)*100, year=2012)  -> contact_shares12

cces_panel14 %>% 
  count(contact) %>% 
  mutate(perc = n / nrow(cces_panel14)*100, year = 2014)  -> contact_shares14

contact_shares_year = contact_shares10 %>%
  bind_rows(., contact_shares12, contact_shares14)

shares_year = ggplot(contact_shares_year, aes(x = factor(year), y = perc, 
                                              fill = factor(contact))) + 
  geom_bar(stat = "identity", position = "dodge") +
  geom_text(aes(label=
                  paste0(I(round(perc, digits = 2)), "%")), 
            position=position_dodge(width=0.9), vjust=-0.45, size = 1.8) +
  scale_fill_manual(name = "Number of Types of Contact", values = c("#ffffcc", "#a1dab4",
                                                                    "#41b6c4", "#2c7fb8",
                                                                    "#253494"),
                    labels = c("0", "1", "2", "3", "4")) +
  labs(x = "Year", y = "Percent of Respondents") +
  ylim(0, 40) +
  theme_bw() +
  theme(legend.position = "bottom")

## Figure A3

## In-person
cces_panel %>% 
  count(in_person) %>% 
  mutate(perc = n / nrow(cces_panel)*100)  -> in_person_shares

in_person = ggplot(in_person_shares, aes(x = factor(in_person), y = perc)) + 
  geom_bar(stat = "identity", color="black", fill="gray") +
  geom_text(aes(label=
                  paste0(I(round(perc, digits = 2)), "%")), 
            position=position_dodge(width=0.9), vjust=-0.45, size = 3) +
  scale_x_discrete(labels= c("No", "Yes")) +
  labs(x = "Contacted: In-Person", y = "Percent of Respondents") +
  ylim(0, 90) +
  theme_bw()


## Phone
cces_panel %>% 
  count(phone) %>% 
  mutate(perc = n / nrow(cces_panel)*100)  -> phone_shares

phone = ggplot(phone_shares, aes(x = factor(phone), y = perc)) + 
  geom_bar(stat = "identity", color="black", fill="gray") +
  geom_text(aes(label=
                  paste0(I(round(perc, digits = 2)), "%")), 
            position=position_dodge(width=0.9), vjust=-0.45, size = 3) +
  scale_x_discrete(labels= c("No", "Yes")) +
  labs(x = "Contacted: Phone", y = "Percent of Respondents") +
  ylim(0, 90) +
  theme_bw()

## Letter
cces_panel %>% 
  count(letter) %>% 
  mutate(perc = n / nrow(cces_panel)*100)  -> letter_shares

letter = ggplot(letter_shares, aes(x = factor(letter), y = perc)) + 
  geom_bar(stat = "identity", color="black", fill="gray") +
  geom_text(aes(label=
                  paste0(I(round(perc, digits = 2)), "%")), 
            position=position_dodge(width=0.9), vjust=-0.45, size =3) +
  scale_x_discrete(labels= c("No", "Yes")) +
  labs(x = "Contacted: Letter or Postcard", y = "Percent of Respondents") +
  ylim(0, 80) +
  theme_bw()

## Email or text
cces_panel %>% 
  count(email_text) %>% 
  mutate(perc = n / nrow(cces_panel)*100)  -> email_text_shares

email_text = ggplot(email_text_shares, aes(x = factor(email_text), y = perc)) + 
  geom_bar(stat = "identity", color="black", fill="gray") +
  geom_text(aes(label=
                  paste0(I(round(perc, digits = 2)), "%")), 
            position=position_dodge(width=0.9), vjust=-0.45, size = 3) +
  scale_x_discrete(labels= c("No", "Yes")) +
  labs(x = "Contacted: Email or Text", y = "Percent of Respondents") +
  ylim(0, 70) +
  theme_bw()

